@extends('web.frame_layout')
<?php $parent_menu = "关于我们"; $menu_selected = "在线留言";?>
<link rel="stylesheet" href="{{asset('web/css/online-msg.css')}}">
@section('content')

        <div class="m-right-nr">
            <div>
                <h2><span>在线留言</span></h2>
            </div>
            <form id="send_message" role="form" action="{{ route('web.feedback.send') }}" method="post">
            <div class="submit-msg" style="margin-left: 25px;">
                <h3>留言内容</h3>
                <textarea name="message"></textarea>
                <label for="message" style="color:red"></label>
                <button>提交留言</button>
            </div>
            </form>
            <div class="dialogue-msg">
                @foreach($feedbacks as $feedback)
                <div>
                    <ul>
                        <li class="leave">
                            <h3><span>留言于</span><span>{{ date("Y-m-d H:i:s",$feedback->time) }}</span></h3>
                            <p>{{ $feedback->content }}</p>
                        </li>
                        @if(!empty($feedback->reply))
                        <li class="reply">
                            <h3><i class="iconfont icon-iconfontguanliyuan-copy"></i><span>管理员</span><span>回复于</span><span>{{ date("Y-m-d H:i:s",$feedback->reply_time) }}</span></h3>
                            <p>{!! $feedback->reply or '无' !!}</p>
                        </li>
                        @endif
                    </ul>
                </div>
                @endforeach
            </div>
            <div class="page">
                @include('web.coms.fenye')
            </div>
        </div>

@endsection

@section('footer')
    <script>
        $("#send_message").validate({
            rules: {
                roles: "required",
                message: {
                    required: true
                }
            }, errorPlacement: function (error, element) {
                $(element).closest("form").find("label[for='" + element.attr("name") + "']").html('请填写留言内容');
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    beforeSend: function () {
                        //禁用按钮,防止重复提交
                        $("button").attr('disabled', 'disabled')
                    },
                    success: function (data) {
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location = "{{ route('web.feedback') }}";
                            }, 1000);
                        } else {
                            $("button").removeAttr('disabled');
                            toastr["error"](data.msg);
                        }
                    }
                });
            }
        });
    </script>
@endsection